package Controller;

import Service.CarService;
import Service.UserService;
import pojo.Car;
import pojo.Customer;
import pojo.RentalRecord;

import java.util.List;

public class UserController {
    private UserService userService;
    private CarService carService;


    public UserController() throws Exception {
        this.userService = new UserService();
        this.carService = new CarService();
    }

    // 调用业务逻辑层的方法更新用户信息（用户在用户界面更新个人信息）
    public Boolean updateUser(Customer customer) {
        // 调用业务逻辑层的方法更新用户信息
        return userService.updateUser(customer);
    }

    //根据用户ID获取个人信息
    public Customer getCustomerById(int userId) throws Exception {
        return userService.getCustomerById(userId);
    }

    //获取所有车辆信息，用户界面
    public List<Car> getAllCars() throws Exception {
        return userService.getAllCars();
    }

    //通过用户id获取用户订单记录
    public List<RentalRecord> getRentalRecordsByCustomerId(int customerId) throws Exception {
        List<RentalRecord> orderList = userService.getRentalRecordsByCustomerId(customerId);
        return orderList;
    }

    //由品牌获取车辆信息展示在用户窗口
    public List<Car> getAllCarsByBrand(String brand) throws Exception {
        List<Car> CarList = carService.getCarByBrand(brand);
        return CarList;
    }

    //用户在用户界面进行还车更新信息
    public Boolean updateRentalRecord(RentalRecord rentalRecord) throws Exception {
        return userService.updateRentalRecord(rentalRecord)&&userService.updateCarByOrder(rentalRecord);
    }

    //用户在用户界面租车时更新car的信息
    public Boolean updateByCar(Car car) throws Exception {
        return carService.updateByCar(car);
    }

    //租车时更新rentalRecord的信息
    public Boolean updateRentalRecord(int carId, int userId) throws Exception {
        return userService.updateRentalRecord(carId,userId);
    }

    //租车时更新个人信息，租车数量
    public Boolean updateUserByRent(Customer customer) throws Exception {
        return userService.updateUserByRent(customer);
    }

    //还车时更新个人信息，租车数量，金钱余额
    public Boolean updateUserByReturn(Customer customer, RentalRecord order) throws Exception {
        return userService.updateUserByReturn(customer,order);
    }
}
